{% extends 'base.twig' %}
{% block style %}
    <link href="/template/plugins/um/themes/default/css/umeditor.css" type="text/css" rel="stylesheet">
    <script type="text/javascript" src="/template/plugins/um/third-party/template.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/template/plugins/um/umeditor.config.js"></script>
    <script type="text/javascript" charset="utf-8" src="/template/plugins/um/umeditor.min.js"></script>
    <script type="text/javascript" charset="utf-8" src="/template/plugins/um/lang/zh-cn/zh-cn.js"></script>
{% endblock %}
{% block content %}
    <section id="main-content">
        <section class="wrapper">
            <div class="row mt">
                <div class="col-lg-12">
                    <div class="form-panel">
                        <h4 class="mb text-info">
                            {% if  product_id %}
                                <i class="fa fa-edit"></i> 编辑
                            {% else %}
                                <i class="fa fa-plus"></i> 新增文章
                            {% endif %}
                            <button class="text-right btn btn-success pull-right"  {% if readonly is null %} onclick="$('#submit').click();" {% endif  %} ><i class="fa fa-save"></i> 保 存 </button>
                        </h4>
                        {% if error %}

                            {% for e in error %}
                                <p class="text-danger bg-warning text-center" style="padding: 5px 0"> ** {{ e.title }} **</p>
                            {% endfor %}

                        {% endif %}

                        <form id='form' name="form" class="form-horizontal style-form" method="post" enctype="multipart/form-data" action="article.php">
                            <input type="hidden" name="article_id" value="{{ article_id }}">
                            <button type="submit" id="submit" class="hidden"></button>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 text-center" > 域名 <br><i class="text-danger">【请添加已设置首页的域名】</i> </label>
                                <div class="col-sm-2">
                                    <input type="text" name="domain" id="domain" value="{{ domain }}" class="form-control" required>
                                </div>
                                <div class="col-sm-6">
                                    <span id="error_domain" class="text-danger"></span>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 text-center" > 标题  </label>
                                <div class="col-sm-10">
                                    <input type="text" name="title" value="{{ title }}" class="form-control" required>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 text-center" > 排序 <br><i class="text-danger">【数值越大越靠前】</i> </label>
                                <div class="col-sm-2">
                                    <input type="text" name="sort" value="{{ sort }}" class="form-control">
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 col-sm-2 text-center" >评价内容 </label>
                                <div class="col-sm-10">
                                    <textarea id="editor" name="content" style="width:101%;height:500px;">{{ content|raw |replace({"img.stosz.com":"imgcn.stosz.com"})}}</textarea>
                                </div>
                            </div>
                            <input type="hidden" name="act" value="save">
                        </form>
                    </div>

                </div>
            </div>
        </section>
    </section>

    <script type="text/javascript">
        highlight_subnav('article.php?');
        $(document).ready(function () {
            var um = UM.getEditor('editor');
        });
        $(function () {
            $("#domain").blur(function () {
                var domain = $(this).val();
                if (domain)
                {
                    $.getJSON('article.php', {domain: domain, act: 'check'},function (data) {
                        if (!data.code)
                        {
                           $('#domain').val('');
                           $('#error_domain').text('该域名还没添加首页');
                        }else{
                           $('#error_domain').text('查询成功');
                        }

                    })
                }
            })
        })
    </script>
{% endblock %}